home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3
/
CHAPTE22
/
EX12.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-29
|
2KB
|
51 lines
#include <genstub.c>
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static BOOL bAnsi = TRUE;
switch (uMsg)
{
case WM_COMMAND:
switch ( LOWORD( wParam ) )
{
case IDM_TEST:
{
TCHAR szBuffer[128];
static WCHAR wc[] = // Declare a Unicode string.
L"This is an example of a wide-char string";
static TCHAR tc[] = // Declare an ANSI string.
"This is an example of a Mulitple-Bytes String";
WCHAR wb[65]; // buffer for wide-chars.
TCHAR tb[65]; // buffer for multiple-byte strings.
HDC hDC = GetDC( hWnd );
// Convert wide to multibyte ANSI.
WideCharToMultiByte( CP_ACP, 0, wc, -1, tb, 64, NULL, NULL );
TextOut( hDC, 0, 0, szBuffer, wsprintf( szBuffer,
"MultipleByte: %s", tc ) );
TextOut( hDC, 0, 20, szBuffer, wsprintf( szBuffer,
"Converted WideChar: %s", tb ) );
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, tb, -1, wb, 64 );
// wide strings should be the same now.
WideCharToMultiByte( CP_ACP, 0, wb, -1, tb, 64, NULL, NULL );
TextOut( hDC, 0, 40, szBuffer, wsprintf( szBuffer,
"Twice-Converted WideChar: %s", tb ) );
ReleaseDC( hWnd, hDC );
}
break;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
}
return( NULL );
}